% 读取图像并灰度化
image = imread('pic_measure.png');
gray_image = rgb2gray(image);

% 使用高斯模糊来降低噪声（可选）
sigma = 2;
smoothed_image = imgaussfilt(gray_image, sigma);

% 应用不同的边缘检测算子
edges_sobel = edge(smoothed_image, 'Sobel');
edges_canny = edge(smoothed_image, 'Canny');
edges_prewitt = edge(smoothed_image, 'Prewitt');
edges_roberts = edge(smoothed_image, 'Roberts');
edges_log = edge(smoothed_image, 'log');

% 显示原图像和边缘检测结果
figure;
subplot(2, 3, 1);
imshow(gray_image);
title('Original Image');

subplot(2, 3, 2);
imshow(edges_sobel);
title('Sobel Edge Detection');

subplot(2, 3, 3);
imshow(edges_canny);
title('Canny Edge Detection');

subplot(2, 3, 4);
imshow(edges_prewitt);
title('Prewitt Edge Detection');

subplot(2, 3, 5);
imshow(edges_roberts);
title('Roberts Edge Detection');

subplot(2, 3, 6);
imshow(edges_log);
title('LoG Edge Detection');


% 保存边缘检测结果到文件
imwrite(edges_sobel, 'edges_sobel.png');
imwrite(edges_canny, 'edges_canny.png');
imwrite(edges_prewitt, 'edges_prewitt.png');
imwrite(edges_roberts, 'edges_roberts.png');
imwrite(edges_log, 'edges_log.png');
